import * as React from "react";

let context = React.createContext();

// 这里设定所想要的全局参数
const initState = {
	isExpand: true,
	userInfo: {},
	areaList: [],
	deptList: [],
	gradeList: [],
	subjectList: [],
	schoolTermList: [],
	teachingMaterialList: [],
	preOrderTypeList: [],
	originalAreaList: [],
	originalTeachingMaterialList: [],
};
// 返回体必须是 Object.assign({}, state);
function reducer(state = {}, action) {
	switch (action.type) {
		case "changeIsExpand":
			state.isExpand = action.data;
			return Object.assign({}, state);
		case "changeUserInfo":
			state.userInfo = action.data;
			return Object.assign({}, state);
		case "changeAreaList":
			state.areaList = action.data;
			return Object.assign({}, state);
		case "changeDeptList":
			state.deptList = action.data;
			return Object.assign({}, state);
		case "changeGradeList":
			state.gradeList = action.data;
			return Object.assign({}, state);
		case "changeSubjectList":
			state.subjectList = action.data;
			return Object.assign({}, state);
		case "changeTermList":
			state.schoolTermList = action.data;
			return Object.assign({}, state);
		case "changeOriginalTeachingMaterialList":
			state.originalTeachingMaterialList = action.data;
			return Object.assign({}, state);
		case "changeTeachingMaterialList":
			state.teachingMaterialList = action.data;
			return Object.assign({}, state);
		case "changePreOrderTypeList":
			state.preOrderTypeList = action.data;
			return Object.assign({}, state);
		case "setOriginalAreaList":
			state.originalAreaList = action.data;
			return Object.assign({}, state);
		default:
			throw new Error();
	}
}

export { initState, context, reducer };
